home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Various / DevDisk 65 (1989)(DevWare PD).zip / DevDisk 65 (1989)(DevWare PD).adf / prosuite / reqsupp.c < prev    next >
C/C++ Source or Header  |  1990-07-11  |  5KB  |  172 lines

  1.  
  2. /* *** reqsupp.c ************************************************************
  3.  *
  4.  * Requester Support Routine
  5.  *     from Book 1 of the Amiga Programmers' Suite by RJ Mical
  6.  *
  7.  * Copyright (C) 1986, 1987, Robert J. Mical
  8.  * All Rights Reserved.
  9.  *
  10.  * Created for Amiga developers.
  11.  * Any or all of this code can be used in any program as long as this
  12.  * entire copyright notice is retained, ok?
  13.  *
  14.  * The Amiga Programmer's Suite Book 1 is copyrighted but freely distributable.
  15.  * All copyright notices and all file headers must be retained intact.
  16.  * The Amiga Programmer's Suite Book 1 may be compiled and assembled, and the 
  17.  * resultant object code may be included in any software product.  However, no 
  18.  * portion of the source listings or documentation of the Amiga Programmer's 
  19.  * Suite Book 1 may be distributed or sold for profit or in a for-profit 
  20.  * product without the written authorization of the author, RJ Mical.
  21.  * 
  22.  * HISTORY      NAME            DESCRIPTION
  23.  * -----------  --------------  --------------------------------------------
  24.  * 4 Feb 87     RJ              Real release
  25.  * 12 Aug 86    RJ >:-{)*       Prepare (clean house) for release
  26.  * 3 May 86     =RJ Mical=      Fix prop gadget for both 1.1 and 1.2
  27.  * 1 Feb 86     =RJ Mical=      Created this file.
  28.  *
  29.  * *********************************************************************** */
  30.  
  31.  
  32. #include <prosuite/prosuite.h>
  33. #include <prosuite/reqsupp.h>
  34.  
  35.  
  36. struct IntuiMessage *GetMsg();
  37.  
  38.  
  39.  
  40. /* *** DoRequest() **********************************************************
  41.  * 
  42.  * NAME
  43.  *     DoRequest  --  Creates and manages a requester
  44.  * 
  45.  * 
  46.  * SYNOPSIS
  47.  *     DoRequest(ReqSupport);
  48.  * 
  49.  * 
  50.  * FUNCTION
  51.  *     Creates a requester according to the specifications laid out
  52.  *     by you in a ReqSupport structure, and manages the interaction
  53.  *     with the requester for you.  In the end this routine returns control
  54.  *     to you with an identifier describing which gadget the user selected
  55.  *     to terminate the requester; this identifier can be found in the
  56.  *     SelectedGadgetID field of your ReqSupport structure.
  57.  * 
  58.  *     Note that if anything goes wrong while trying to create the 
  59.  *     requester (usually out of memory) this routine returns 
  60.  *     immediately with the SelectedGadgetID field set to zero.
  61.  *     Because of this, you should either avoid GadgetIDs of zero
  62.  *     or at least you should have your Cancel Gadget have an
  63.  *     ID of zero.
  64.  * 
  65.  *     You can specify routines that will be called when certain events
  66.  *     occur while the requester is displayed.  For instance, you can
  67.  *     specify that a particular routine be called every time the
  68.  *     user selects any of the requester gadgets.  See the documentation
  69.  *     and the ReqSupport structure for details about what
  70.  *     routine vectors you can supply.
  71.  * 
  72.  * 
  73.  * INPUTS
  74.  *     ReqSupport = pointer to a ReqSupport structure
  75.  * 
  76.  * 
  77.  * RESULT
  78.  *     Returns the identifier of the gadget that ended the requester
  79.  *     in the ReqSupport's SelectedGadgetID field.
  80.  *     If anything goes wrong (usually out of memory) the SelectedGadgetID
  81.  *     field is set to zero.
  82.  */
  83. VOID DoRequest(reqsupp)
  84. struct ReqSupport *reqsupp;
  85. {
  86.     ULONG class;
  87.     SHORT x, y;
  88.     struct IntuiMessage *message;
  89.     struct Gadget *gadget;
  90.     ULONG saveidcmp;
  91.     BOOL IAintGotNoSatisfaction, mousemoved;
  92.     struct Window *window;
  93.     LONG seconds, micros;
  94.  
  95.     window = reqsupp->Window;
  96.  
  97.     saveidcmp = window->IDCMPFlags;
  98.     ModifyIDCMP(window, 
  99.             GADGETUP | GADGETDOWN | REQSET | REQCLEAR
  100.             | MOUSEMOVE | DISKINSERTED | MOUSEBUTTONS);
  101.  
  102.     if (Request(&reqsupp->Requester, window) == FALSE)
  103.         {
  104.         reqsupp->SelectedGadgetID = 0;
  105.         goto JUMP_SHIP;
  106.         }
  107.  
  108.     IAintGotNoSatisfaction = TRUE;
  109.  
  110.     while (IAintGotNoSatisfaction)
  111.         {
  112.         Wait(1 << window->UserPort->mp_SigBit);
  113.  
  114.         mousemoved = FALSE;
  115.  
  116.         while (message = GetMsg(window->UserPort))
  117.             {
  118.             gadget = (struct Gadget *)message->IAddress;
  119.             class = message->Class;
  120.             x = message->MouseX;
  121.             y = message->MouseY;
  122.             seconds = message->Seconds;
  123.             micros = message->Micros;
  124.             ReplyMsg(message);
  125.  
  126.             switch (class)
  127.                 {
  128.                 case MOUSEBUTTONS:
  129.                     break;
  130.                 case REQSET:
  131.                     /* Does the caller have some startup 
  132.                      * stuff to perform now that the
  133.                      * requester has been opened?
  134.                      */
  135.                     if (reqsupp->StartRequest)
  136.                         (*reqsupp->StartRequest)();
  137.                     break;
  138.                 case DISKINSERTED:
  139.                     if (reqsupp->NewDiskHandler) (*reqsupp->NewDiskHandler)();
  140.                     break;
  141.                 case MOUSEMOVE:
  142.                     mousemoved = TRUE;
  143.                     break;
  144.                 case GADGETDOWN:
  145.                 case GADGETUP:
  146.                     reqsupp->SelectedGadgetID = gadget->GadgetID;
  147.                     if (reqsupp->GadgetHandler)
  148.                         {
  149.                         if ((*reqsupp->GadgetHandler)(gadget, 
  150.                                 x, y, seconds, micros))
  151.                             {
  152.                             EndRequest(&reqsupp->Requester, window);
  153.                             IAintGotNoSatisfaction = FALSE;
  154.                             }
  155.                         }
  156.                     break;
  157.                 case REQCLEAR:
  158.                     IAintGotNoSatisfaction = FALSE;
  159.                     break;
  160.                 }
  161.             }
  162.  
  163.         if (mousemoved && reqsupp->MouseMoveHandler)
  164.             (*reqsupp->MouseMoveHandler)();
  165.         }
  166.  
  167. JUMP_SHIP:
  168.     ModifyIDCMP(window, saveidcmp);
  169. }
  170.  
  171.  
  172.